exports = this
$ = jQuery


$ ->
  DOUBAN.apikey = '0a1cdbf7264ac2f51e5693e572e048df'
  $('#id_isbn').bind('change',
    (e)->
      _isbn = $(this).val()
      console.log _isbn
      DOUBAN.getISBNBook(
        isbn:_isbn
        callback:(re) ->
          book = DOUBAN.parseSubject(re)
          console.log(book)
          $('#id_title').val(book.title)
          $('#id_subtitle').val()
          $('#id_pages').val(book.attribute['pages'])
          $('#id_author').val(book.author['name'])
          $('#id_price').val(book.attribute['price'][0])
          $('#id_publisher').val(book.attribute['publisher'][0])
          $('#id_pubdate').val(book.attribute['pubdate'][0])
          $('#id_cover_img').val(book.link['image'])
          $('#id_summary').val(book.summary)
          $('#id_author_intro').val(book.attribute['author-intro'][0])
          @
      )
#      $.getJSON("http://api.douban.com/book/subject/isbn/#{_isbn}?alt=xd&callback=?",
#        (data)->
#          console.log data
#          $('#id_title').val(data.title['$t'])
#          $('#id_subtitle').val()
#      )
  )